//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================



using System;
using System.Collections.Generic;
using System.Text;
using LitwareHR.Portfolio.Gateways;
using Shp.Runtime.Contract;

namespace LitwareHR.PrivateApp.Presenters.ConfigCusto
{
    public class EditMainMenuPresenter
    {
        private IEditMainMenuView _view;

        public EditMainMenuPresenter(IEditMainMenuView view)
        {
            _view = view;
        }

        private EditMainMenuPresenter()
        {
        }

        public void OnViewLoaded()
        {
            MainMenuItem[] list = PresentationGateway.GetMainMenuList();
            _view.ShowMainMenuItems(list);
        }

        public void OnAdd(string description, bool isPublic, string url, MainMenuItem[] menuItems)
        {
            List<MainMenuItem> tmp = new List<MainMenuItem>(menuItems);
            MainMenuItem item = new MainMenuItem();
            item.Description = description;
            item.IsPublic = isPublic;
            item.Url = url;
            tmp.Add(item);
            _view.ShowMainMenuItems(tmp.ToArray());
            _view.ResetForm();
        }

        public void OnRemove(int index, MainMenuItem[] menuItems)
        {
            List<MainMenuItem> tmp = new List<MainMenuItem>(menuItems);
            tmp.RemoveAt(index);            
            _view.ShowMainMenuItems(tmp.ToArray());
        }

        public void OnSave(MainMenuItem[] menuItems)
        {
            PresentationGateway.UpdateMainMenu(menuItems);
        }
    }
}
